<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();
need_auth('super');
/*need_auth('market');*/

if (is_post()){
	$action = strval($_POST['action']);

	if ( 'charge' == $action ) {
		$username = strval($_POST['username']);
		$credit = intval($_POST['credit']);
		if (is_numeric($username)) $u = Table::Fetch('user', $username);
		elseif (strpos($username, '@')) $u = Table::Fetch('user', $username, 'email');
		else $u = Table::Fetch('user', $username, 'username');
		if ($u && $credit) {
			ZCredit::Create($credit, $u['id'], 'charge', 0);
            log_admin('credit', $u['username'].'用户积分充值',$u);
			redirect(null, '用户积分充值成功！');
		}
	}
	else if ( 'settings' == $action ) {
		$INI['credit']['register'] = abs((real)($_POST['credit']['register']));
		$INI['credit']['login'] = abs((real)($_POST['credit']['login']));
		$INI['credit']['invite'] = abs((real)($_POST['credit']['invite']));
		$INI['credit']['buy'] = abs((real)($_POST['credit']['buy']));
		$INI['credit']['pay'] = 0 + ($_POST['credit']['pay']);
		$INI['credit']['charge'] = 0 + ($_POST['credit']['charge']);
        $INI['credit']['comment'] = abs(intval($_POST['credit']['comment']));
		configure_save('credit');
        log_admin('credit', '设置积分规则',$_POST);
		redirect(null, '设置积分规则成功！');
	}
}

$INI['credit']['register'] = abs((real)($INI['credit']['register']));
$INI['credit']['login'] = abs((real)($INI['credit']['login']));
$INI['credit']['invite'] = abs((real)($INI['credit']['invite']));
$INI['credit']['buy'] = abs((real)($INI['credit']['buy']));
$INI['credit']['comment'] = abs((real)($INI['credit']['comment']));
$INI['credit']['pay'] = 0 + ($INI['credit']['pay']);
$INI['credit']['charge'] = 0 + ($INI['credit']['charge']);

include template('manage_credit_settings');
